package com.lagou.penglei.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ascetic
 * @version 1.0
 * @ClassName ZKConfig
 * @Description TODO
 * @date 2020-07-04 14:56
 */
@Configuration
public class ZKConfig {


    @Bean
    public CuratorFramework zkClinet() {
        RetryPolicy exponentialBackoffRetry = new ExponentialBackoffRetry(1000, 3);

        CuratorFramework  client = CuratorFrameworkFactory.builder()
                .connectString("127.0.0.1:2181")
                .sessionTimeoutMs(50000)
                .connectionTimeoutMs(30000)
                .retryPolicy(exponentialBackoffRetry)
//                .namespace("dataBase")  // 独立的命名空间 /base
                .build();

        client.start();

        return client;
    }
}